/**
 * Zhz.net Inc.
 * Copyright (c) 2004-2010 All Rights Reserved.
 */
package com.zhz.lib.cms.manage;

import java.net.URLDecoder;
import java.net.URLEncoder;
import java.util.List;

import javax.servlet.http.HttpServletRequest;

import com.zhz.project.common.util.alibaba.StringUtil;
import com.zhz.project.common.util.zhzutil.ZhzHttpRequestUtil;

/**
 *
 * @author Administrator
 * @version $Id: BaseActionWithSearch.java, v 0.1 Sep 21, 2010 5:20:56 PM Administrator Exp $
 */
public class BaseActionWithSearch extends BaseAction {

    /**
     * 根据搜索框的值构造查询语句，进行翻页
     *
     * @param request
     * @param table
     * @param key
     * @param entryTatal
     * @param whereStatement
     * @param LIST
     */
    @Override
    @SuppressWarnings("unchecked")
    protected List getListWithFanyeHref(HttpServletRequest request, final String table,
                                        String whereStatement, final String order, String list,
                                        StringBuffer fanyeHref) {

        // ///////////////////////////////////////
        // 构造搜索框进行查询

        // 获取搜索框的类型
        String keywordType = ZhzHttpRequestUtil.getParameters(request, "keywordType");
        // 获取搜索框的值
        String keyword = ZhzHttpRequestUtil.getParameters(request, "keyword");
        if (StringUtil.isNotBlank(keyword)) {
            request.setAttribute("keywordOld", URLDecoder.decode(keyword));
        }
        String keywordOut = null;
        // 根据搜索框的值进行查询
        if (StringUtil.isNotBlank(keyword)) {
            keyword = URLDecoder.decode(keyword);
            keywordOut = URLEncoder.encode(URLEncoder.encode(keyword));
            whereStatement += " and " + keywordType + " like '%" + keyword + "%'";
            fanyeHref.append("&keyword=");
            fanyeHref.append(keywordOut);
            fanyeHref.append("&keywordType=");
            fanyeHref.append(keywordType);
        }

        request.setAttribute("keyword", keywordOut);
        request.setAttribute("keywordType", ZhzHttpRequestUtil
            .getParameters(request, "keywordType"));

        return super.getListWithFanyeHref(request, table, whereStatement, order, list, fanyeHref);

    }
}
